/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.api.mgrInterface;

import com.inspur.edp.bef.dtgenerator.DotNetToJavaStringHelper;
import com.inspur.edp.bef.dtgenerator.api.ApiHelper;
import com.inspur.edp.bef.dtgenerator.api.BefApiGeneratorContext;
import com.inspur.edp.bef.dtgenerator.api.mgrInterface.method.MgrMethodBuildUtil;
import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.MgrInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.MgrInterfaceGeneratorContext;

import java.util.ArrayList;

public class BEMgrInterfaceGenerator extends MgrInterfaceGenerator {
  public BefApiGeneratorContext apiGenContext;

  public BEMgrInterfaceGenerator(BefApiGeneratorContext apiGenContext) {
    super(apiGenContext);
    this.apiGenContext = apiGenContext;
  }
// keyword:
  // ORIGINAL LINE: protected new  beMgrInterfaceGenCtxgetContext() { return
  // (BeMgrInterfaceGenCtx)super.getContext(); }
  @Override
  protected BeMgrInterfaceGenCtx getContext() {
    return (BeMgrInterfaceGenCtx) super.getContext();
  }

  @Override
  protected MgrInterfaceGeneratorContext createMgrInterfaceGenContext() {
    return new BeMgrInterfaceGenCtx(apiGenContext);
  }

  @Override
  protected String getName() {
    return ApiHelper.getBEMgrInterfaceClassName(apiGenContext.getBeGenCtx().getBE());
  }

  @Override
  protected java.util.ArrayList<TypeInfo> addParentInterfaces() {
    java.util.ArrayList<TypeInfo> result = new ArrayList<>();
    // wj-dbe已改
    if (DotNetToJavaStringHelper.isNullOrEmpty(
        apiGenContext.getBeGenCtx().getBE().getDependentEntityId())
        || apiGenContext.getBeGenCtx().getIsParentBEInSameProj()) {
      return null;
    }
    TypeInfo parentType =
        new TypeInfo(
            ApiHelper.getBEMgrInterfaceClassName(apiGenContext.getBeGenCtx().getParentBE()));
    parentType.setTypePackageName(apiGenContext.getParentNamespace());
    result.add(parentType);
    return result;
  }

  @Override
  protected ArrayList<BaseGenerator> createChildGenerators() {
    ArrayList<BaseGenerator> list = super.createChildGenerators();
    if (list == null) {
      list = new ArrayList<>();
    }
    MgrMethodBuildUtil.addBizActionGenerators(list, apiGenContext);
    MgrMethodBuildUtil.addDefaultActionGenerators(list, apiGenContext);
    return list;
  }
}
